<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>菜品管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
	<style>
	#ggnamediv .layui-input,#ggvaldiv .layui-input{ display:inline;height:30px}
	#ggvaldiv .thumb_img {margin-right: 5px;}
	</style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-card layui-col-md12">
				<div class="layui-card-header">
					{if !$info['id']}<i class="fa fa-plus"></i> 添加菜品{else}<i class="fa fa-pencil"></i> 编辑菜品{/if}
					<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
				</div>
				<div class="layui-card-body" pad15>
					<div class="layui-form">
						<div class="layui-tab" lay-filter="mytab">
							<ul class="layui-tab-title">
								<li class="layui-this" lay-id="1">菜品信息</li>
								<li lay-id="2">菜品详情</li>
							</ul>
							<div class="layui-tab-content">
								<div class="layui-tab-item layui-show">
									<input type="hidden" name="id" value="{$info['id']}"/>
									{if input('param.bid')}<input type="hidden" name="info[bid]" value="{$Request.param.bid}"/>{/if}
									<div class="layui-form-item">
										<label class="layui-form-label">菜品名称：</label>
										<div class="layui-input-inline" style="width:400px">
											<input type="text" name="info[name]" lay-verify="required" lay-verType="tips" class="layui-input" value="{$info['name']}">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">菜品主图：</label>
										<input type="hidden" name="info[pic]" id="pic" lay-verType="tips" class="layui-input" value="{$info['pic']}">
										<button style="float:left;" type="button" class="layui-btn layui-btn-primary" upload-input="pic" upload-preview="picPreview" onclick="uploader(this)">上传图片</button>
										<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：640×640像素</div>
										<div id="picPreview" style="float:left;padding-top:10px;padding-left:110px;clear: both;">
											<div class="layui-imgbox" style="width:100px;"><div class="layui-imgbox-img"><img src="{$info['pic']}"/></div></div>
										</div> 
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">菜品图片：</label>
										<input type="hidden" name="info[pics]" value="{$info['pics']}" id="pics">
										<button style="float:left;" type="button" class="layui-btn layui-btn-primary" onclick="uploader(this,true)" upload-input="pics" upload-preview="picList" >批量上传</button>
										<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：640×640像素</div>
										<div id="picList" style="float:left;padding-top:10px;padding-left:110px;clear: both;">
											{if $info['pics']}{php}$pics = explode(',',$info['pics']);{/php}{foreach $pics as $pic}
											<div class="layui-imgbox">
												<a class="layui-imgbox-close" href="javascript:void(0)" onclick="$(this).parent().remove();getpicsval('pics','picList')" title="删除"><i class="layui-icon layui-icon-close-fill"></i></a>
												<span class="layui-imgbox-img"><img src="{$pic}"></span>
											</div>
											{/foreach}{/if}
										</div>
									</div>
									<!-- <div class="layui-form-item" >
										<label class="layui-form-label">菜品卖点：</label>
										<div class="layui-input-inline" style="width:400px">
											<input type="text" name="info[sellpoint]" class="layui-input" value="{$info['sellpoint']}">
										</div>
										<div class="layui-form-mid layui-word-aux">在菜品详情页标题下面展示卖点信息，建议60字以内</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">菜品编码：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[procode]" class="layui-input" value="{$info['procode']}">
										</div>
									</div> -->
									<div class="layui-form-item">
										<label class="layui-form-label">菜品分类：</label>
										<div class="layui-input-inline" style="width:300px">
											<select name="info[cid]" id="cid" xm-select="selectCid" xm-select-max="5" xm-select-search >
												<option value="">--请选择--</option>
											{foreach $clist as $cv}
												<option value="{$cv['id']}" {if in_array($cv['id'],$info['cid'])}selected{/if}>{$cv['name']}</option>
												{foreach $cv['child'] as $k=>$v}
												{if $k < count($cv['child'])-1}
												<option value="{$v['id']}" {if in_array($v['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;├ {$v['name']}</option>
												{else}
												<option value="{$v['id']}" {if in_array($v['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;└ {$v['name']}</option>
												{/if}
													{foreach $v['child'] as $k2=>$v2}
													{if $k2 < count($v['child'])-1}
													<option value="{$v2['id']}" {if in_array($v2['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├ {$v2['name']}</option>
													{else}
													<option value="{$v2['id']}" {if in_array($v2['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└ {$v2['name']}</option>
													{/if}
													{/foreach}
												{/foreach}
											{/foreach}
											</select>
										</div>
										<div class="layui-form-mid layui-word-aux">最多可选5个分类</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">出餐区域：</label>
										<div class="layui-input-inline" style="width:300px">
											<select name="info[area_id]" id="area_id">
												<option value="">--请选择--</option>
												{foreach $area_list as $cv}
												<option value="{$cv['id']}" {if $cv['id'] == $info['area_id']}selected{/if}>{$cv['name']}</option>
												{/foreach}
											</select>
										</div>
										<div class="layui-form-mid layui-word-aux">绑定出餐区域，用户下单后可分区域打印小票</div>
									</div>

									<div class="layui-form-item" id="setgg">
										<label class="layui-form-label">设置规格：</label>
										<div class="layui-input-inline" style="width:auto">
											<table id="ggnamediv"  class="layui-table" style="width:600px">
												<thead>
												<tr>
													<th>规格分组</th>
													<th>规格名称</th>
													<th>操作</th>
												</tr>
												</thead>
												{php} $guigedata = json_decode($info['guigedata']);{/php}
												{if $guigedata}
												{foreach $guigedata as $k=>$gg}
												<tr>
													<td><input type="text" class="layui-input" name="ggname" value="{$gg->title}" style="width:120px"/></td>
													<td>
														{foreach $gg->items as $k2=>$ggitem}
														<div><input type="text" class="layui-input"style="width:180px" value="{$ggitem->title}" placeholder="请输入规格名称">
															{if $k2==0}
															<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggname(this)" style="margin-top:-3px;"><i class="fa fa-plus" style="font-size:14px!important"></i></button>
															{else}
															<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().remove()" style="margin-top:-3px;"><i class="fa fa-remove" style="font-size:14px!important"></i></button>
															{/if}
														</div>
														{/foreach}
													</td>
													{if $k==0}
													<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggtype()">添加</button></td>
													{else}
													<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button></td>
													{/if}
												</tr>
												{/foreach}
												{else}
												<tr>
													<td><input type="text" class="layui-input" name="ggname" value="规格" style="width:120px"/></td>
													<td><div><input type="text" class="layui-input" style="width:180px" value="默认规格" placeholder="请输入规格名称"> <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggname(this)" style="margin-top:-3px;"><i class="fa fa-plus" style="font-size:14px!important"></i></button></div></td>
													<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggtype()">添加</button></td>
												</tr>
												{/if}
											</table>
											<div class="layui-word-aux">提示：先点击“添加按钮”添加规格分组，如：“口味”，“餐量”，若只有一种规格则不需要添加规格分组；<br/>然后分别点击"＋"号添加规格名称，如：“微辣”，“中辣”；“大份”，“小份”；<br/>设置完成后点击“刷新规格项目表”按钮进行编辑各个规格的价格、库存等信息</div>
											<button type="button"  class="layui-btn layui-btn-sm layui-btn-primary" onclick="refreshgg()"><i class="fa fa-refresh" style="font-size:14px!important"></i>刷新规格项目表</button>
											
											<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="lvpriceset()" id="lvpricebtn">{if $info['lvprice']==1}关闭{else}开启{/if}会员价</button>
											<input type="hidden" name="info[lvprice]" value="{$info['id']?$info['lvprice']:'0'}"/>
											
											<table id="ggvaldiv" class="layui-table" style="margin-top:20px;">
											</table>
											
<!--											<table id="ggvaldiv" class="layui-table" style="margin-top:20px;">-->
<!--												<thead>-->
<!--													<tr>-->
<!--														<th>规格</th>-->
<!--														<th>市场价（元）</th>-->
<!--														<th>成本价（元）</th>-->
<!--														{if $info['lvprice']==1}-->
<!--														{foreach $levellist as $level}-->
<!--														<th class="level-price">{$level.name}（元）</th>-->
<!--														{/foreach}-->
<!--														{else}-->
<!--														<th class="sell-price">销售价（元）</th>-->
<!--														{/if}-->
<!--														<th>每日库存</th>-->
<!--														<th>总库存</th>-->
<!--														{if $bid==0}<th>赠{:t('积分')}(个)</th>{/if}-->
<!--														<th>图片</th>-->
<!--														<th>操作</th>-->
<!--													</tr>-->
<!--												</thead>-->
<!--												{php} $i=0;$ksLast = 0;{/php}-->
<!--												{if $guige_list}-->
<!--												{foreach $guige_list as $ks => $gg}-->
<!--												<tr data-ks="{$ks}">-->
<!--													<td>-->
<!--														<input name="option[{$ks}][name]" type="text" value="{$gg['name']}" class="layui-input"/>-->
<!--													</td>-->
<!--													<td>-->
<!--														<input name="option[{$ks}][market_price]" type="text" class="layui-input" style="width:70px" value="{if $gg['market_price']!=null}{$gg['market_price']}{/if}"/>-->
<!--														{if $i == 0}-->
<!--														 <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('market_price')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													<td>-->
<!--														<input name="option[{$ks}][cost_price]" type="text" class="layui-input" style="width:70px" value="{if $gg['cost_price']!=null}{$gg['cost_price']}{/if}"/>-->
<!--														{if $i == 0}-->
<!--														 <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('cost_price')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													{if $info['lvprice']==1}-->
<!--														{foreach $levellist as $lk=>$level}-->
<!--														<td class="level-price">-->
<!--															<input name="option[{$ks}][sell_price_{$level.id}]" type="text"-->
<!--																   style="width:70px" value="{if $gg['lvprice_data']==null || $gg['lvprice_data'][$level['id']]!=null}{$gg['lvprice_data'][$level['id']]}{/if}" class="layui-input" id="levelprice_{$i}_{$lk}"/>-->
<!--															{if $i == 0}-->
<!--															{if $lk==0}-->
<!--															<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('sell_price_{$level.id}')"></i>-->
<!--															{else}-->
<!--															<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plsetlevelprice({$i},'{$lk}')"></i>-->
<!--															{/if}-->
<!--															{/if}-->
<!--														</td>-->
<!--													{/foreach}-->

<!--													{else}-->
<!--													<td class="sell-price">-->
<!--														<input name="option[{$ks}][sell_price]" type="text" style="width:70px" value="{if $gg['sell_price']!=null}{$gg['sell_price']}{/if}" class="layui-input"/>-->
<!--														{if $i == 0}-->
<!--														 <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('sell_price')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													{/if}-->
<!--													<td>-->
<!--														<input name="option[{$ks}][stock_daily]" type="text" style="width:60px" value="{if $gg['stock_daily']!=null}{$gg['stock_daily']}{/if}" class="layui-input"/>-->
<!--														{if $i == 0}-->
<!--													 	<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('stock_daily')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													<td>-->
<!--														<input name="option[{$ks}][stock]" type="text" style="width:60px" value="{if $gg['stock']!=null}{$gg['stock']}{/if}" class="layui-input"/>-->
<!--														{if $i == 0}-->
<!--														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('stock')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													{if $bid==0}-->
<!--													<td>-->
<!--														<input name="option[{$ks}][givescore]" type="text" style="width:60px" value="{if $gg['givescore']!=null}{$gg['givescore']}{/if}" class="layui-input"/>-->
<!--														{if $i == 0}-->
<!--														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('givescore')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													{/if}-->
<!--													<td id="ggpic{$ks}">-->
<!--														<input type="hidden" name="option[{$ks}][pic]" id="ggpicval{$ks}" value="{if $gg['pic']!=null}{$gg['pic']}{/if}"/><img class="thumb_img" src="{if $gg['pic']!=null}{$gg['pic']}{/if}" style="max-width:50px;"/><button class="layui-btn layui-btn-sm layui-btn-primary" onclick="uploader(this)" upload-input="ggpicval{$ks}" upload-preview="ggpic{$ks}" type="button">上传</button>-->
<!--													</td>-->
<!--													{if $i == 0}-->
<!--													<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addGuige()">添加</button></td>-->
<!--													{else}-->
<!--													<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delGuige(this)">删除</button></td>-->
<!--													{/if}-->
<!--												</tr>-->
<!--												{php} $i++; if($i == count($guige_list)) $ksLast = $ks;{/php}-->
<!--												{/foreach}-->
<!--												{else}-->
<!--												<tr data-ks="0">-->
<!--													<td>-->
<!--														<input name="option[0][name]" type="text" value="默认规格" class="layui-input"/>-->
<!--													</td>-->
<!--													<td>-->
<!--														<input name="option[0][market_price]" type="text" class="layui-input" style="width:70px" value=""/>-->
<!--														{if $i == 0}-->
<!--														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('market_price')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													<td>-->
<!--														<input name="option[0][cost_price]" type="text" class="layui-input" style="width:70px" value=""/>-->
<!--														{if $i == 0}-->
<!--														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('cost_price')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													{if $info['lvprice']==1}-->
<!--													{foreach $levellist as $lk=>$level}-->
<!--													<td class="level-price">-->
<!--														<input name="option[0][sell_price_{$level.id}]" type="text" style="width:70px" value="" class="layui-input" id="levelprice_0_{$lk}"/>-->
<!--														{if $i == 0}-->
<!--														{if $lk==0}-->
<!--														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('sell_price_{$level.id}')"></i>-->
<!--														{else}-->
<!--														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plsetlevelprice({$i},'{$lk}')"></i>-->
<!--														{/if}-->
<!--														{/if}-->
<!--													</td>-->
<!--													{/foreach}-->

<!--													{else}-->
<!--													<td class="sell-price">-->
<!--														<input name="option[0][sell_price]" type="text" style="width:70px" value="" class="layui-input"/>-->
<!--														{if $i == 0}-->
<!--														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('sell_price')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													{/if}-->
<!--													<td>-->
<!--														<input name="option[0][stock_daily]" type="text" style="width:60px" value="1000" class="layui-input"/>-->
<!--														{if $i == 0}-->
<!--														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('stock_daily')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													<td>-->
<!--														<input name="option[0][stock]" type="text" style="width:60px" value="1000" class="layui-input"/>-->
<!--														{if $i == 0}-->
<!--														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('stock')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													{if $bid==0}-->
<!--													<td>-->
<!--														<input name="option[0][givescore]" type="text" style="width:60px" value="0" class="layui-input"/>-->
<!--														{if $i == 0}-->
<!--														<i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset('givescore')"></i>-->
<!--														{/if}-->
<!--													</td>-->
<!--													{/if}-->
<!--													<td id="ggpic">-->
<!--														<input type="hidden" name="option[0][pic]" id="ggpicval" value=""/>-->
<!--														<img class="thumb_img" src="" style="max-width:50px;"/>-->
<!--														<button class="layui-btn layui-btn-sm layui-btn-primary" onclick="uploader(this)" upload-input="ggpicval" upload-preview="ggpic" type="button">上传</button>-->
<!--													</td>-->
<!--													<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addGuige()">添加</button></td>-->
<!--												</tr>-->
<!--												{/if}-->
<!--											</table>-->
<!--										-->
											<div class="layui-form-mid layui-word-aux">注：开启会员价可设置不同会员等级显示不同价格；赠{:t('积分')}确认收货才赠送，与系统设置中的消费赠送{:t('积分')}(支付就赠送{:t('积分')})兼得</div>
											<input type="hidden" name="specs" value=""/>
										</div>
									</div>

									{if getcustom('product_jialiao')}
									<div class="layui-form-item">
										<label class="layui-form-label">售卖加料：</label>
										<div class="layui-input-inline" style="width:300px">
											<table id="jlnamediv"  class="layui-table" style="width:600px">
												<thead>
												<tr>
													<th>加料名称</th>
													<th>价格</th>
													<th>操作</th>
												</tr>
												</thead>
												{php} $jialiaodata = json_decode($info['jialiaodata']);{/php}
												{if $jialiaodata}
													{foreach $jialiaodata as $k=>$gg}
													<tr>
														<td ><input type="text" placeholder="请输入加料名称" class="layui-input" name="jltitle" value="{$gg->jltitle}" lay-verify="required" /></td>
														
														<td ><input type="number" class="layui-input" value="{$gg->price}"   min="0" placeholder="请输入价格" lay-verify="required|positiveNumberRequiredTrue" name="price"></td>
														
														{if $k==0}
														<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addjialiao()">添加</button></td>
														{else}
														<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button></td>
														{/if}
													</tr>
													{/foreach}
												{else}
												<tr>
													<td ><input type="text" class="layui-input" name="jltitle" value="" placeholder="请输入加料名称" lay-verify="required" /></td>
													
													<td ><input type="number" name="price" class="layui-input"  value="0.00" placeholder="请输入价格" lay-verify="required|positiveNumberRequiredTrue" min="0"></td>
													
													<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addjialiao()">添加</button></td>
												</tr>
												{/if}
											</table>
										</div>
									</div>
									
									 {/if}
									
									{if $bid==0 || $bset['commission_canset']==1}
									<div class="layui-form-item">
										<label class="layui-form-label">分销设置：</label>
										<div class="layui-input-block" style="width:750px">
											<input type="radio" name="info[commissionset]" value="0" {if !$info['id'] || $info['commissionset']==0}checked{/if} title="按照{:t('会员')}等级" lay-filter="commissionset">
											<input type="radio" name="info[commissionset]" value="1" {if $info['commissionset']==1}checked{/if} title="单独设置提成比例" lay-filter="commissionset">
											<input type="radio" name="info[commissionset]" value="2" {if $info['commissionset']==2}checked{/if} title="单独设置提成金额" lay-filter="commissionset">
											<input type="radio" name="info[commissionset]" value="3" {if $info['commissionset']==3}checked{/if} title="分销送{:t('积分')}" lay-filter="commissionset">
											<input type="radio" name="info[commissionset]" value="-1" {if $info['commissionset']==-1}checked{/if} title="不参与分销" lay-filter="commissionset">
										</div>
										<div class="layui-form-mid layui-word-aux">按照{:t('会员')}等级：按照{:t('会员')}等级中设置的提成比例进行提成分配，提成=对应{:t('会员')}等级的提成比例×{$jiesuantypeDesc}×购买数量<br>
										单独设置提成比例：按照单独设置的提成比例进行提成分配，提成=设置的百分比×{$jiesuantypeDesc}×购买数量<br>
										单独设置提成金额：按照单独设置的提成金额进行提成分配，提成=提成金额×购买数量<br>
										分销送{:t('积分')}：分销提成不给{:t('佣金')}而是给{:t('积分')}，得到的积分=提成{:t('积分')}×购买数量
										</div>
									</div>
									{php}
									$commissiondata1 = json_decode($info['commissiondata1'],true);
									if(!$commissiondata1) $commissiondata1 = [];
									$commissiondata2 = json_decode($info['commissiondata2'],true);
									if(!$commissiondata2) $commissiondata2 = [];
									$commissiondata3 = json_decode($info['commissiondata3'],true);
									if(!$commissiondata3) $commissiondata3 = [];
									{/php}
									<div id="commissionset1" {if $info['commissionset']!=1}style="display:none"{/if}>
										{if !$aglevellist}
										<div class="layui-form-item">
											<label class="layui-form-label">提成比例：</label>
											<div class="layui-form-mid" style="color:red">未设置具有分销权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置分销权限</div>
										</div>
										{else}
										{foreach $aglevellist as $level}
										<div class="layui-form-item">
											<label class="layui-form-label">{$level.name}：</label>
											<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important"> 一级(%) </div>
											<div class="layui-input-inline" style="width: 100px;">
												<input style="border-radius:0 2px 2px 0" type="text" name="commissiondata1[{$level.id}][commission1]" class="layui-input" value="{$commissiondata1[$level['id']]['commission1']}">
											</div>
											{if $level['can_agent']>1}
											<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important">二级(%)</div>
											<div class="layui-input-inline" style="width: 100px;">
												<input style="border-radius:0 2px 2px 0" type="text" name="commissiondata1[{$level.id}][commission2]" class="layui-input" value="{$commissiondata1[$level['id']]['commission2']}">
											</div>
											{/if}
											{if $level['can_agent']>2}
											<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important">三级(%)</div>
											<div class="layui-input-inline" style="width: 100px;">
												<input style="border-radius:0 2px 2px 0" type="text" name="commissiondata1[{$level.id}][commission3]" class="layui-input" value="{$commissiondata1[$level['id']]['commission3']}">
											</div>
											{/if}
										</div>
										{/foreach}
										{/if}
									</div>
									<div id="commissionset2" {if $info['commissionset']!=2}style="display:none"{/if}>
										{if !$aglevellist}
										<div class="layui-form-item">
											<label class="layui-form-label">提成金额：</label>
											<div class="layui-form-mid" style="color:red">未设置具有分销权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置分销权限</div>
										</div>
										{else}
										{foreach $aglevellist as $level}
										<div class="layui-form-item">
											<label class="layui-form-label">{$level.name}：</label>
											<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important"> 一级(元) </div>
											<div class="layui-input-inline" style="width: 100px;">
												<input style="border-radius:0 2px 2px 0" type="text" name="commissiondata2[{$level.id}][commission1]" class="layui-input" value="{$commissiondata2[$level['id']]['commission1']}">
											</div>
											{if $level['can_agent']>1}
											<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important">二级(元)</div>
											<div class="layui-input-inline" style="width: 100px;">
												<input style="border-radius:0 2px 2px 0" type="text" name="commissiondata2[{$level.id}][commission2]" class="layui-input" value="{$commissiondata2[$level['id']]['commission2']}">
											</div>
											{/if}
											{if $level['can_agent']>2}
											<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important">三级(元)</div>
											<div class="layui-input-inline" style="width: 100px;">
												<input style="border-radius:0 2px 2px 0" type="text" name="commissiondata2[{$level.id}][commission3]" class="layui-input" value="{$commissiondata2[$level['id']]['commission3']}">
											</div>
											{/if}
										</div>
										{/foreach}
										{/if}
									</div>
									<div id="commissionset3" {if $info['commissionset']!=3}style="display:none"{/if}>
										{if !$aglevellist}
										<div class="layui-form-item">
											<label class="layui-form-label">提成{:t('积分')}：</label>
											<div class="layui-form-mid" style="color:red">未设置具有分销权限的{:t('会员')}等级，请先在[{:t('会员')}]-[等级及分销]设置分销权限</div>
										</div>
										{else}
										{foreach $aglevellist as $level}
										<div class="layui-form-item">
											<label class="layui-form-label">{$level.name}：</label>
											<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important"> 一级({:t('积分')}) </div>
											<div class="layui-input-inline" style="width: 100px;">
												<input style="border-radius:0 2px 2px 0" type="text" name="commissiondata3[{$level.id}][commission1]" class="layui-input" value="{$commissiondata3[$level['id']]['commission1']}">
											</div>
											{if $level['can_agent']>1}
											<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important">二级({:t('积分')})</div>
											<div class="layui-input-inline" style="width: 100px;">
												<input style="border-radius:0 2px 2px 0" type="text" name="commissiondata3[{$level.id}][commission2]" class="layui-input" value="{$commissiondata3[$level['id']]['commission2']}">
											</div>
											{/if}
											{if $level['can_agent']>2}
											<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important">三级({:t('积分')})</div>
											<div class="layui-input-inline" style="width: 100px;">
												<input style="border-radius:0 2px 2px 0" type="text" name="commissiondata3[{$level.id}][commission3]" class="layui-input" value="{$commissiondata3[$level['id']]['commission3']}">
											</div>
											{/if}
										</div>
										{/foreach}
										{/if}
									</div>
									{/if}
									{if $bid==0}
									<div class="layui-form-item">
										<label class="layui-form-label">{:t('积分')}抵扣：</label>
										<div class="layui-input-block" style="width:800px">
											<input type="radio" name="info[scored_set]" value="0" {if !$info['id'] || $info['scored_set']==0}checked{/if} title="按照系统设置抵扣" lay-filter="scored_set">
											<input type="radio" name="info[scored_set]" value="1" {if $info['scored_set']==1}checked{/if} title="单独设置抵扣比例" lay-filter="scored_set">
											<input type="radio" name="info[scored_set]" value="2" {if $info['scored_set']==2}checked{/if} title="单独设置抵扣金额" lay-filter="scored_set">
											<input type="radio" name="info[scored_set]" value="-1" {if $info['scored_set']==-1}checked{/if} title="不可用{:t('积分')}抵扣" lay-filter="scored_set">
										</div>
									</div>
									<div id="scored_set1" {if $info['scored_set']!=1 && $info['scored_set']!=2}style="display:none"{/if}>
										<div class="layui-form-item">
											<label class="layui-form-label"></label>
											<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important">最多抵扣(<span id="scoredkmaxunit">{$info['scored_set']==1?'%':'元'}</span>) </div>
											<div class="layui-input-inline">
												<input type="text" name="info[scored_val]" value="{$info.scored_val}" class="layui-input">
											</div>
										</div>
									</div>
									{/if}
									<div class="layui-form-item">
										<label class="layui-form-label">显示销量：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[sales]" value="{$info['id']?$info['sales']:'0'}" class="layui-input">
											<input type="hidden" name="info[oldsales]" value="{$info['id']?$info['sales']:'0'}" class="layui-input">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">起售数量：</label>
										<div class="layui-input-inline">
											<input type="number" name="info[limit_start]" value="{$info['id']?$info['limit_start']:'0'}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">多少份起卖，0表示不限购</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">每单限购：</label>
										<div class="layui-input-inline">
											<input type="number" name="info[limit_per]" min="0" value="{$info['id']?$info['limit_per']:'0'}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">每单最多可购买多少份，0表示不限购</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">周几可点：</label>
										<div class="layui-input-block">
											<input type="checkbox" name="info[status_week][]" value="1" title="周一" {if (in_array(1, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="2" title="周二" {if (in_array(2, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="3" title="周三" {if (in_array(3, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="4" title="周四" {if (in_array(4, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="5" title="周五" {if (in_array(5, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="6" title="周六" {if (in_array(6, $info['status_week']))} checked=""{/if}>
											<input type="checkbox" name="info[status_week][]" value="7" title="周日" {if (in_array(7, $info['status_week']))} checked=""{/if}>
										</div>
										<div class="layui-form-mid layui-word-aux">每桌最多可购买多少份，0表示不限购</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">打包费：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[pack_fee]" value="{$info['id']?$info['pack_fee']:'0'}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">打包费根据购买数量计算</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">序号：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[sort]" value="{$info['id']?$info['sort']:'0'}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">用于排序,越大越靠前</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">状态：</label>
										<div class="layui-input-inline" style="width:600px">
											<input type="radio" name="info[status]" value="1" title="已上架" {if !$info['id'] || $info['status']==1}checked{/if} lay-filter="set_status"/>
											<input type="radio" name="info[status]" value="0" title="未上架" {if $info['id'] && $info['status']==0}checked{/if} lay-filter="set_status"/>
											<input type="radio" name="info[status]" value="2" title="设置上架时间" {if $info['id'] && $info['status']==2}checked{/if} lay-filter="set_status"/>
											<input type="radio" name="info[status]" value="3" title="设置上架周期" {if $info['id'] && $info['status']==3}checked{/if} lay-filter="set_status"/>
										</div>
									</div>
									
									<div class="layui-form-item" id="set_status2" {if $info['status']!=2}style="display:none"{/if}>
										<label class="layui-form-label">上架时间：</label>
										<div class="layui-input-inline" style="width:150px">
											<input type="text" name="info[start_time]" class="layui-input" value="{$info.start_time}" id="start_time" autocomplete="off">
										</div>
										<div class="layui-form-mid">到</div>
										<div class="layui-input-inline" style="width:150px">
											<input type="text" name="info[end_time]" class="layui-input" value="{$info.end_time}" id="end_time" autocomplete="off">
										</div>
										<div class="layui-form-mid layui-word-aux" style="clear:left;margin-left:110px"></div>
									</div>
									<div class="layui-form-item" id="set_status3" {if $info['status']!=3}style="display:none"{/if}>
										<label class="layui-form-label">上架周期：</label>
										<div class="layui-input-inline" style="width:150px">
											<input type="text" name="info[start_hours]" class="layui-input" value="{$info.start_hours}" id="start_hours" autocomplete="off">
										</div>
										<div class="layui-form-mid">到</div>
										<div class="layui-input-inline" style="width:150px">
											<input type="text" name="info[end_hours]" class="layui-input" value="{$info.end_hours}" id="end_hours" autocomplete="off">
										</div>
										<div class="layui-form-mid layui-word-aux" style="clear:left;margin-left:110px">结束时间小于或等于开始时间表示跨天,如:16:00到06:00表示下午4点到次日早晨6点</div>
									</div>
									
									<div class="layui-form-item">
										<div class="layui-input-block">
											<button class="layui-btn layui-btn-normal" onclick="gonext(2)">下一步:编辑菜品详情</button>
											<button class="layui-btn layui-btn-danger" lay-submit lay-filter="formsubmit">提 交</button>
										</div>
									</div>

								</div>
								<div class="layui-tab-item">
									<!-- 详情编辑器 -->
									<!-- <div class="layui-form-item">
										<label class="layui-form-label">菜品详情</label>
										<div class="layui-input-inline" style="width:500px">
											<script id="content" name="info[detail]" type="text/plain" style="width:100%;height:500px">{$info['detail']}</script>
										</div>
									</div> -->
									<!-- 详情编辑器 -->
									{if $info['detail_text'] || $info['detail_pics']}
									<div class="layui-form-item">
										<label class="layui-form-label" style="width:110px">菜品详情(文本)：</label>
										<div class="layui-input-inline" style="width:500px">
											<textarea name="info[detail_text]" placeholder="请输入菜品详情内容" class="layui-textarea">{$info.detail_text}</textarea>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label" style="width:110px">菜品详情(图片)：</label>
										<input type="hidden" name="info[detail_pics]" value="{$info['detail_pics']}" id="detail_pics">
										<button style="float:left;" type="button" class="layui-btn layui-btn-primary" onclick="uploader(this,true)" upload-input="detail_pics" upload-preview="detail_picsPreview" >批量上传</button>
										<div class="layui-form-mid layui-word-aux" style="margin-left:10px;"></div>
										<div id="detail_picsPreview" style="float:left;padding-top:10px;padding-left:140px;clear: both;">
											{if $info['detail_pics']}{php}$pics = explode(',',$info['detail_pics']);{/php}{foreach $pics as $pic}
											<div class="layui-imgbox">
												<a class="layui-imgbox-close" href="javascript:void(0)" onclick="$(this).parent().remove();getpicsval('detail_pics','detail_picsPreview')" title="删除"><i class="layui-icon layui-icon-close-fill"></i></a>
												<span class="layui-imgbox-img"><img src="{$pic}"></span>
											</div>
											{/foreach}{/if}
										</div>
									</div>
									{/if}
									<?php
									$pagetitle='菜品详情';
									$pagedata= $info['detail'] && json_decode($info['detail']) ? $info['detail'] : '[{"id":"M0000000000000","temp":"richtext","params":{bgcolor:"#FFFFFF",margin_x:"0",margin_y:"0",padding_x:"10",padding_y:"10","quanxian":{"all":true},"platform":{"all":true}},"data":"","other":"","content":""}]';
									?>
									{include file="designer_page/designer_editor" /}

									<div class="layui-form-item">
										<div class="layui-input-block">
											<button class="layui-btn layui-btn-normal" onclick="gonext(1)">上一步:编辑菜品信息</button>
											<button class="layui-btn layui-btn-danger" lay-submit lay-filter="formsubmit">提 交</button>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
  </div>
	<video id="myvideo" style="display:none"></video>
	<script>
		layui.form.verify({
			positiveNumberRequiredTrue:[/^(([0-9]+[\.]?[0-9]+)|[1-9])$/,'只能填写正数'],//必填，且只能输入正数
		})
		var formSelects = layui.formSelects;

	$(".layui-form input#video").bind("input change propertychange",function(event){
		var videourl = $('#video').val();
		if(videourl){
			$("#myvideo").prop("src", videourl);
			$("#myvideo")[0].addEventListener("loadedmetadata", function() {
				var tol = Math.floor(this.duration); //获取总时长
				$('#video_duration').val(tol);
			});
		}else{
			$('#video_duration').val(0);
		}
	})
	//var ueditor = UE.getEditor('content');
	layui.form.on('radio(freighttypeset)', function(data){
		if(data.value == '1'){
			$('#setfreight').hide();
		}else{
			$('#setfreight').show();
		}
	})

	layui.form.on('switch(isfuwu)',function(data){
		if(data.elem.checked){
			$('#isfuwudiv').show();
		}else{
			$('#isfuwudiv').hide();
		}
	})
	layui.form.on('radio(commissionset)', function(data){
		if(data.value == '1'){
			$('#commissionset1').show();
			$('#commissionset2').hide();
			$('#commissionset3').hide();
		}else if(data.value == '2'){
			$('#commissionset1').hide();
			$('#commissionset2').show();
			$('#commissionset3').hide();
		}else if(data.value == '3'){
			$('#commissionset1').hide();
			$('#commissionset2').hide();
			$('#commissionset3').show();
		}else{
			$('#commissionset1').hide();
			$('#commissionset2').hide();
			$('#commissionset3').hide();
		}
	});
	layui.form.on('radio(scored_set)', function(data){
		if(data.value == '1'){
			$('#scored_set1').show();
			$('#scoredkmaxunit').html('%');
		}else if(data.value == '2'){
			$('#scored_set1').show();
			$('#scoredkmaxunit').html('元');
		}else{
			$('#scored_set1').hide();
		}
	})
	
	layui.laydate.render({ 
		elem: '#start_hours',
		type: 'time',
		format:'HH:mm',
		trigger: 'click'
	});
	layui.laydate.render({ 
		elem: '#end_hours',
		type: 'time',
		format:'HH:mm',
		trigger: 'click'
	});
	layui.laydate.render({ 
		elem: '#start_time',
		type: 'datetime',
		trigger: 'click'
	});
	layui.laydate.render({ 
		elem: '#end_time',
		type: 'datetime',
		trigger: 'click'
	});
	layui.form.on('radio(set_status)',function(data){
		if(data.value=="0" || data.value=="1"){
			$('#set_status2').hide();
			$('#set_status3').hide();
		}
		if(data.value=="2"){
			$('#set_status2').show();
			$('#set_status3').hide();
		}
		if(data.value=="3"){
			$('#set_status2').hide();
			$('#set_status3').show();
		}
	});
	function gonext(layid){
		$(window).scrollTop(0);
		layui.element.tabChange('mytab', layid);
	}
	layui.element.on('tab(mytab)', function(){
		try{
			changeconentxy();
		}catch(e){}
	})
	//var ueditor = UE.getEditor('editor');
	//售卖加料
	function addjialiao(){
		var num	= $('#jlnamediv').find('tr').length;
		 if(num >= 11){
		 	 layer.alert('最多添加10个');
		 	 return;
		 }
		var gghtml = '<tr>';
		gghtml += '<td ><input type="text" class="layui-input" name="jltitle" value="" placeholder="请输入加料名称" lay-verify="required" /></td>';
		gghtml += '<td ><input type="number" class="layui-input" name="price" value="0.00" placeholder="请输入价格" lay-verify="required|positiveNumberRequiredTrue" min="0"></td>';
		gghtml += '<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button></td>';
		gghtml += '</tr>';
		$('#jlnamediv').append(gghtml);
	}	
		
		
	var oldgglist = {:json_encode($guige_list)};
	$(function(){
		 refreshgg();
	})
	function addggtype(){
		var gghtml = '<tr>';
		gghtml += '<td><input type="text" name="ggname" class="layui-input" value="" style="width:120px" placeholder="请输入规格分组"/></td>';
		gghtml += '<td><div><input type="text" class="layui-input" style="width:180px" value="" placeholder="请输入规格名称"> <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="addggname(this)" style="margin-top:-3px;"><i class="fa fa-plus" style="font-size:14px!important"></i></button></div></td>';
		gghtml += '<td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().parent().remove()">删除</button></td>';
		gghtml += '</tr>';
		$('#ggnamediv').append(gghtml);
	}
	function addggname(obj){
		var ggnameobj = $(obj).parent().parent().append('<div><input class="layui-input" type="text" style="width:180px" value="" placeholder="请输入规格名称"> <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="$(this).parent().remove()" style="margin-top:-3px;"><i class="fa fa-remove" style="font-size:14px!important"></i></button></div>');
	}
	function lvpriceset(){
		var lvprice = $("input[name='info[lvprice]']").val();
		if(lvprice == 0){
			$("input[name='info[lvprice]']").val('1');
			$('#lvpricebtn').text('关闭会员价');
			$('#commissionset4input').show();
			$('#commissionset4tips').show();
			//layui.form.render();
		}else{
			$("input[name='info[lvprice]']").val('0');
			$('#lvpricebtn').text('开启会员价');
			$('#commissionset4input').hide();
			$('#commissionset4tips').hide();
		}
		refreshgg()
	}
	var specs = [];
	function refreshgg(){
		var haskong = 0
		$('#ggnamediv').find("input").each(function(){
			if($(this).val()=='') haskong = 1
		})
		if(haskong){
			layer.msg('请填写完整');return;
		}
		var lvprice = $("input[name='info[lvprice]']").val();
		specs = [];
		var i=0;
		$('input[name=ggname]').each(function(){
			var ggval = [];
			var j=0;
			$(this).parent().next().find('input').each(function(){
				ggval.push({ 'k':j,'title':$(this).val()});
				j++
			})
			specs.push({ 'k':i,'title':$(this).val(),'items':ggval});
			i++;
		});
		console.log(specs)
		var len = specs.length;
		var newlen = 1;
		var h = new Array(len);
		var rowspans = new Array(len);

		var html = '<thead><tr>';
		for(var i=0;i<len;i++){
			html+="<th>" + specs[i].title + "</th>";
			var itemlen = specs[i].items.length;
			if(itemlen<=0) { itemlen = 1 };
			newlen*=itemlen;
			h[i] = new Array(newlen);
			for(var j=0;j<newlen;j++){
				h[i][j] = new Array();
			}
			var l = specs[i].items.length;
			rowspans[i] = 1;
			for(j=i+1;j<len;j++){
				rowspans[i]*= specs[j].items.length;
			}
		}
		// html += '<th>规格编号</th>';
		html += '<th>市场价（元）</th>';
		html += '<th>成本价（元）</th>';
		if(lvprice==1){
			{foreach $levellist as $level}
			html += '<th>{$level.name}（元）</th>';
			{/foreach}
			}else{
				html += '<th>销售价（元）</th>';
			}
			html += '<th>每日库存</th>';
			html += '<th>总库存</th>';
			{if $bid==0}
			html += '<th>赠{:t('积分')}(个)</th>';
			{/if}
					html += '<th>图片</th>';
					html += '</tr></thead>';

					for(var m=0;m<len;m++){
						var k = 0,kid = 0,n=0;
						for(var j=0;j<newlen;j++){
							var rowspan = rowspans[m];
							if( j % rowspan==0){
								h[m][j]={ k:specs[m].items[kid].k,title: specs[m].items[kid].title, html: "<td rowspan='" +rowspan + "'>"+ specs[m].items[kid].title+"</td>\r\n",id: specs[m].items[kid].id};
							}else{
								h[m][j]={ k:specs[m].items[kid].k,title:specs[m].items[kid].title, html: "",id: specs[m].items[kid].id};
							}
							n++;
							if(n==rowspan){
								kid++; if(kid>specs[m].items.length-1) { kid=0; }
								n=0;
							}
						}
					}

					var hh = "";
					for(var i=0;i<newlen;i++){
						hh+="<tr>";
						var ks = [];
						var titles = [];
						for(var j=0;j<len;j++){
							hh+=h[j][i].html;
							ks.push( h[j][i].k);
							titles.push( h[j][i].title);
						}
						ks2 =ks.join('_');
						ks =ks.join(',');
						titles =titles.join(',');
						if(typeof(oldgglist[ks])!='undefined'){
							var val = oldgglist[ks];
						}else{
							var val = { market_price:'',cost_price:'',sell_price:'',stock:'1000',givescore:'0',pic:'',lvprice_data:null};
						}

						//hh += '<td>';
						//hh += '	<input name="option['+ks+'][procode]" class="layui-input" type="text" style="width:100px" value="'+(val.procode==null?'':val.procode)+'"/>';
						//if(i==0){
						//	hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'procode\')"></i>';
						//}
						// hh += '</td>';
						// hh += '<td>';
						// hh += '	<input name="option['+ks+'][barcode]" class="layui-input" type="text" style="width:100px" value="'+(val.barcode==null?'':val.barcode)+'"/>';
						// if(i==0){
						// 	hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'barcode\')"></i>';
						// }
						// hh += '</td>';
						hh += '<td>';
						hh += '	<input name="option['+ks+'][name]" type="hidden" value="'+titles+'" class="layui-input"/><input name="option['+ks+'][market_price]" type="text" class="layui-input" style="width:70px" value="'+(val.market_price==null?'':val.market_price)+'"/>';
						if(i==0){
							hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'market_price\')"></i>';
						}
						hh += '</td>';
						hh += '<td>';
						hh += '	<input name="option['+ks+'][cost_price]" type="text" class="layui-input" style="width:70px" value="'+(val.cost_price==null?'':val.cost_price)+'"/>';
						if(i==0){
							hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'cost_price\')"></i>';
						}
						hh += '</td>';
						if(lvprice==1){
							{foreach $levellist as $lk=>$level}
							hh += '<td>';
							hh += '	<input name="option['+ks+'][sell_price_{$level.id}]" type="text" style="width:70px" value="'+(val.lvprice_data==null || val.lvprice_data[{$level.id}]==null?'':val.lvprice_data[{$level.id}])+'" class="layui-input" id="levelprice_'+i+'_{$lk}"/>';
							if(i==0){
								{if $lk==0}
								hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'sell_price_{$level.id}\')"></i>';
								{else}
								hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plsetlevelprice(\''+i+'\',\'{$lk}\')"></i>';
								{/if}
								}
								hh += '</td>';
								{/foreach}
								}else{
									hh += '<td>';
									hh += '	<input name="option['+ks+'][sell_price]" type="text" style="width:70px" value="'+(val.sell_price==null?'':val.sell_price)+'" class="layui-input"/>';
									if(i==0){
										hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'sell_price\')"></i>';
									}
									hh += '</td>';
								}
								
								hh += '<td>';
								hh += ' <input name="option['+ks+'][stock_daily]" type="number" min="0" style="width:60px" value="'+(val.stock_daily<=0?'0':val.stock_daily)+'" class="layui-input"/>';
								if(i==0){
									hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'stock_daily\')"></i>';
								}
								hh += '</td>';
							
								hh += '<td>';
								hh += ' <input name="option['+ks+'][stock]" type="text" style="width:60px" value="'+(val.stock==null?'':val.stock)+'" class="layui-input"/>';
								if(i==0){
									hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'stock\')"></i>';
								}
								hh += '</td>';
								{if $bid==0}
								hh += '<td>';
								hh += ' <input name="option['+ks+'][givescore]" type="text" style="width:60px" value="'+(val.givescore==null?'':val.givescore)+'" class="layui-input"/>';
								if(i==0){
									hh += ' <i class="fa fa-hand-o-down" style="cursor:pointer" title="批量设置" onclick="plset(\'givescore\')"></i>';
								}
								hh += '</td>';
								{/if}
									
										hh += '<td id="ggpic'+ks2+'"><input type="hidden" name="option['+ks+'][pic]" id="ggpicval'+ks2+'" value="'+(val.pic==null?'':val.pic)+'"/><img class="thumb_img" src="'+(val.pic==null?'':val.pic)+'" style="max-width:50px;"/> <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="uploader(this)" upload-input="ggpicval'+ks2+'" upload-preview="ggpic'+ks2+'" type="button">上传</button></td>';
										hh += "</tr>";
									}
									html+=hh;
									$("#ggvaldiv").html(html);
								}
								function plset(name){
									if(name =='procode'){
										var procode = $("input[name$='["+name+"]']").eq(0).val();
										if(procode == '') procode = randomString(6);
										$("input[name$='["+name+"]']").each(function(i,v){
											if(i>0) $(this).val(procode+ '-'+i);
										})
									}else{
										$("input[name$='["+name+"]']").val($("input[name$='["+name+"]']").eq(0).val());
									}
								}
								function plsetlevelprice(i,k){
									var thisprice = $('#levelprice_'+i+'_'+k).val();
									console.log(thisprice)
									var level0price = $('#levelprice_0_0').val();
									console.log(level0price)
									var pricepercent = thisprice / level0price;
									console.log(pricepercent)
									$("input[name$='][market_price]']").each(function(i2,v2){
										var this_price = $('#levelprice_'+i2+'_0').val() * pricepercent;
										console.log(this_price)
										this_price = parseInt(this_price*100)/100;
										$('#levelprice_'+i2+'_'+k).val(this_price);
									})
								}
								function randomString(len) {
									len = len || 32;
									var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
									var maxPos = $chars.length;
									var pwd = '';
									for (i = 0; i < len; i++) {
										pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
									}
									return pwd;
								}

								layui.form.on('checkbox(gettjset)', function(data){
									console.log(data)
									if(data.elem.checked){
										$('#gettjset').hide();
									}else{
										$('#gettjset').show();
									}
								});
								var chooseUrlField = '';
								function chooseUrl2(field){
									chooseUrlField = field;
									layer.open({type:2,shadeClose:true,area:['1100px', '650px'],'title':'选择链接',content:"{:url('DesignerPage/chooseurl')}&callback=chooseLink2"})
								}
								function chooseLink2(urlname,url){
									$("#"+chooseUrlField).val(url);
								}

								function showChooseCategory(){
									layer.open({type:2,title:'选择类目',content:"{:url('Wxvideo/allcategory')}&ischoose=1",area:['900px','600px'],shadeClose:true});
								}
								function chooseCategory(data){
									console.log(data)
									$("input[name='info[wxvideo_third_cat_id]']").val(data.third_cat_id);
								}

								/**
								 * 1.监听select的选中与取消
								 *
								 * formSelects.on(ID, Function);
								 *
								 * @param ID        xm-select的值
								 * @param Function  自定义处理方法
								 * @param isEnd     是否获取实时数据, true/false
								 */
								var formSelects = layui.formSelects;
								var paramdata='{$info[\'paramdata\']}';
								// console.log('paramdata')
								// console.log(paramdata)
								formSelects.on('selectCid', function(id, vals, val, isAdd, isDisabled){
									//console.log($("input[name='info[cid]']").val())
									var cid = $("input[name='info[cid]']").val();
									$.post("{:url('getParam')}",{cid:cid},function(data){
										if(data.status == 1){
											var paramlist = data.paramlist;
											var html = '';
											for(var i=0;i<paramlist.length;i++){
												html += '<div class="layui-form-item">';
												html += '	<label class="layui-form-label">';
												if(paramlist[i]['is_required']==1) html += '<span class="redstar">*</span>';
												html += paramlist[i]['name'];html += '：</label>';
												if(paramlist[i]['type']=='0'){
													html += '<div class="layui-input-inline" style="width:240px">';
													html += '<input type="text" class="layui-input" name="paramdata['+paramlist[i]['name']+']" ';
													if(typeof (paramdata[paramlist[i]['name']]) != 'undefined')
														html +=' value="'+ paramdata[paramlist[i]['name']]+'"';
													if(paramlist[i]['is_required']==1) html += ' lay-verify="required" lay-verType="tips"';
													html += ' placeholder="'+paramlist[i]['tips']+'"/>';
													html += '</div>';
												}else if(paramlist[i]['type']=='1'){
													html += '<div class="layui-input-inline" style="width:240px">';
													html += '	<select name="paramdata['+paramlist[i]['name']+']"';
													if(paramlist[i]['is_required']==1) html += ' lay-verify="required" lay-verType="tips"';
													html += '	>';
													html += '<option value="">'+paramlist[i]['tips']+'</option>';
													//console.log(paramlist[i]['params'])
													var parsms = JSON.parse(paramlist[i]['params']);
													for(var j=0;j<parsms.length;j++){
														if (paramdata[paramlist[i]['name']] == parsms[j]){
															html += '<option selected>'+parsms[j]+'</option>';
														}else{
															html += '<option>'+parsms[j]+'</option>';
														}
													}
													html += '</select></div>';
												}else if(paramlist[i]['type']=='2'){
													html += '<div class="layui-input-inline" style="width:240px">';
													var parsms = JSON.parse(paramlist[i]['params']);
													for(var j=0;j<parsms.length;j++){
														html += '<input type="checkbox" name="paramdata['+paramlist[i]['name']+'][]" value="'+parsms[j]+'" title="'+parsms[j]+'" lay-skin="primary" ';
														if(Array.isArray(paramdata[paramlist[i]['name']]) && paramdata[paramlist[i]['name']].indexOf(parsms[j]) != -1) html += ' checked';
														html += ' />';
													}
													html += '</div>';
													html += '<div class="layui-form-mid layui-word-aux" style="clear:left;margin-left:130px">{$param.tips}</div>';
												}

												html += '</div>';

											}
											if(paramlist.length == 0){
												html = '<div class="layui-form-item"><label class="layui-form-label"></label><div class="layui-form-mid">暂未添加商品参数或当前商品分类下无参数，<a href="javascript:void(0)" onclick="openmax(\'{:url(\'ShopParam/index\')}&isopen=1\')">去添加</a></div></div>';
											}
// console.log(html);
											$(".paramTab").html(html);

											layui.form.render();
										}
									})
									//id:           点击select的id
									//vals:         当前select已选中的值
									//val:          当前select点击的值
									//isAdd:        当前操作选中or取消
									//isDisabled:   当前选项是否是disabled

									//如果return false, 那么将取消本次操作
									// return false;
								},true);
	
</script>

	<script>
	{if getcustom('product_jialiao')}
	function getjialiao(){
		var jldata = [];
		var i=0;
		$('input[name=jltitle]').each(function(){
			var price=	$(this).parent().next().find('input').val();
			jldata.push({'jltitle':$(this).val(),'price':price});
			i++;
		});
		return   jldata;
	}
	{/if}
	layui.form.on('submit(formsubmit)', function(obj){
		var field = obj.field
		field.specs = JSON.stringify(specs)
		{if getcustom('product_jialiao')}
		var jldata=getjialiao();
	
		 field.jldata = JSON.stringify(jldata)
		{/if}
		//field['info[detail]'] = ueditor.getContent();
		field['info[detail]'] = geteditordata();
		//console.log(field);return;
		if(field['info[freighttype]'] == 0 && field['info[freightdata]'] == ''){
			dialog('请选择运费模板');
			return;
		}
		var index = layer.load();
		$.post("{:url('save')}",field,function(data){
			layer.close(index);
			dialog(data.msg,data.status);
			if(data.status == 1){
				setTimeout(function(){
					parent.layer.closeAll();
					parent.tableIns.reload()
				},1000)
			}
		})
	})
  </script>
	{include file="public/copyright"/}
</body>
</html>